/**
 * Created by Administrator on 2016/8/22.
 */
NodeList.prototype.forEach = Array.prototype.forEach;
var nbq_images_survey = [];
var pdx_images_survey = [];
var dbx_images_survey = [];

var path_survey = 'http://pm.ht-home.cn/api/others/getSurveyInfoFoShare.json?projectId='+window.currentProjectId;
var xhr_survey = null;
if (window.XMLHttpRequest) {
    // 非IE内核
    xhr_survey = new XMLHttpRequest();
}
xhr_survey.open('get', path_survey, true);
xhr_survey.send(null);
xhr_survey.onreadystatechange = function () {
    if (xhr_survey.readyState === 4) {
        if (xhr_survey.status === 200) {
            var jsonData_survey = JSON.parse(xhr_survey.responseText);
            BindData_survey(jsonData_survey);
            Check_survey();
        }
    }
};

function BindData_survey(jsonData) {

    var data = jsonData.data;
    document.getElementById("l1_t1_survey").innerHTML = typeof data.surveyResult === 'undefined' ? ''  : data.surveyResult;
    document.getElementById("l1_t2_survey").innerHTML = typeof data.causation === 'undefined' ? ''  : data.causation;
    //---------------------------------------------
    document.getElementById("l2_t1_survey").innerHTML = typeof data.jsf === 'undefined' ? ''  : data.jsf;
    document.getElementById("l2_t2_survey").innerHTML = typeof data.jzjgnf === 'undefined' ? ''  : data.jzjgnf;
    document.getElementById("l2_t3_survey").innerHTML = typeof data.fwjg === 'undefined' ? ''  : data.fwjg;
    document.getElementById("l2_t4_survey").innerHTML = typeof data.wdlx === 'undefined' ? ''  : data.wdlx;
    if (jsonData.data.wdjg == '其它') {
        document.getElementById("l2_t5_survey").innerHTML = typeof data.wdjgQt === 'undefined' ? ''  : data.wdjgQt;
    } else {
        document.getElementById("l2_t5_survey").innerHTML = typeof data.wdjg === 'undefined' ? ''  : data.wdjg;
    }
    document.getElementById("l2_t6_survey").innerHTML = typeof data.wdhz === 'undefined' ? ''  : data.wdhz;
    document.getElementById("l2_t7_survey").innerHTML = typeof data.buildingHeight === 'undefined' ? ''  : data.buildingHeight +'m';
    document.getElementById("l2_t8_survey").innerHTML = typeof data.floors === 'undefined' ? ''  : data.floors;
    document.getElementById("l2_t9_survey").innerHTML = typeof data.zwwz === 'undefined' ? ''  : data.zwwz;
    document.getElementById("l2_t10_survey").innerHTML = typeof data.zwgd === 'undefined' ? ''  : data.zwgd;
    //---------------------------------------------
    document.getElementById("l3_t1_survey").innerHTML = typeof data.jhdy === 'undefined' ? ''  : data.jhdy;
    document.getElementById("l3_t2_survey").innerHTML = typeof data.wmfld === 'undefined' ? ''  : data.wmfld;
    document.getElementById("l3_t3_survey").innerHTML = typeof data.jxzkgrl === 'undefined' ? ''  : data.jxzkgrl;
    //---------------------------------------------
    for (var i = 0; i < jsonData.data.spmsSurveyWmList.length; i++) {
        var newNode = document.createElement('div');
        var html = '<div class="line"></div>';
        var value = jsonData.data.spmsSurveyWmList[i];
        var str = '<li class="list-content"><span class="content-span-left">';
        var str1 = '<span class="content-span_survey">';
        html += '<li class="list-content"><span class="content-span-high">屋面' + (i + 1) + '</span></li>';
        html += '<div class="line-short"></div>';
        html += str + '屋面倾角</span>';
        html += str1 + (typeof value.wmqj === 'undefined' ? ''  : value.wmqj) + '<span style="color: #ccc">度</span></span></li>';
        html += str + '屋面朝向</span>';
        html += str1 + (typeof value.wdcx === 'undefined' ? ''  : value.wdcx) + '<span style="color: #ccc">度</span></span></li>';
        html += str + '屋面长度</span>';
        html += str1 + (typeof value.wmLong === 'undefined' ? ''  : value.wmLong) + '<span style="color: #ccc">cm</span></span></li>';
        html += str + '屋面宽度</span>';
        html += str1 + (typeof value.wmWeith === 'undefined' ? ''  : value.wmWeith) + '<span style="color: #ccc">cm</span></span></li>';
        html += str + '女儿墙高度</span>';
        html += str1 + (typeof value.nrqHeigth === 'undefined' ? ''  : value.nrqHeigth) + '<span style="color: #ccc">cm</span></span></li>';
        html += str + '屋面凸起遮挡物情况</span>';
        html += str1 + (typeof value.wmtq === 'undefined' ? ''  : value.wmtq) + '</span></li>';
        html += str + '屋面厚度</span>';
        html += str1 + (typeof value.wmhd === 'undefined' ? ''  : value.wmhd) + '<span style="color: #ccc">cm</span></span></li>';
        html += str + '防水方案</span>';
        html += str1 + (typeof value.fsfa === 'undefined' ? ''  : value.fsfa) + '</span></li>';
        html += str + '屋面形状</span>';
        html += str1 + (typeof value.wmxz === 'undefined' ? ''  : value.wmxz) + '</span></li>';
        html += str + '本屋面屋顶类型</span>';
        html += str1 + (typeof value.bwwdlx === 'undefined' ? ''  : value.bwwdlx) + '</span></li>';
        newNode.innerHTML = html;
        document.getElementById("wm_survey").appendChild(newNode);
    }

    //---------------逆变器图-----------------------
    var index1 = search_index_survey('NBQAZWZ', jsonData);
    var images = jsonData.data.classList[index1];
    if (images && images.NBQAZWZ && images.NBQAZWZ.length) {
        for (var i = 0; i < images.NBQAZWZ.length; i++) {
            var newNode = document.createElement('img');
            var type = "nbq";
            var url = images.NBQAZWZ[i].smallImageUrl;
            newNode.setAttribute("onclick", "useHammer_survey(event," + i + ",'" + type + "')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            nbq_images_survey[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("nbq_img_survey").appendChild(newNode);
        }
    } else {
        document.getElementById("nbq_img_survey").style.display = 'none';
    }

    //---------------配电箱图-----------------------
    var index1 = search_index_survey('PDXAZWZ', jsonData);
    images = jsonData.data.classList[index1];
    if (images && images.PDXAZWZ && images.PDXAZWZ.length) {
        for (var i = 0; i < images.PDXAZWZ.length; i++) {
            var newNode = document.createElement('img');
            var type = 'pdx';
            var url = images.PDXAZWZ[i].smallImageUrl;
            newNode.setAttribute("onclick", "useHammer_survey(event," + i + ",'" + type + "')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            pdx_images_survey[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("pdx_img_survey").appendChild(newNode);
        }
    } else {
        document.getElementById("pdx_img_survey").style.display = 'none';
    }

    //---------------电表箱图-----------------------
    var index2 = search_index_survey('YDBXWZ', jsonData);
    images = jsonData.data.classList[index2];
    if (images && images.YDBXWZ.length && images.YDBXWZ) {
        for (var i = 0; i < images.YDBXWZ.length; i++) {
            var newNode = document.createElement('img');
            var type = 'dbx';
            var url = images.YDBXWZ[i].smallImageUrl;
            newNode.setAttribute("onclick", "useHammer_survey(event," + i + ",'" + type + "')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            dbx_images_survey[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("dbx_img_survey").appendChild(newNode);
        }
    } else {
        document.getElementById("dbx_img_survey").style.display = 'none';
    }
    changeImage_survey();
}


function search_index_survey(str, data) {
    for (var i = 0; i < data.data.classList.length; i++) {
        for (var k in data.data.classList[i]) {
            if (k == str) {
                return i;
            }
        }
    }
    return 0;
}//寻找对应key的序号


//----------------------调整图片-----------------------
function changeImage_survey() {
    var images = document.querySelectorAll('.image');

    if (typeof (images[0]) != 'undefined') {
        var imageWidth = images[0].offsetWidth;
        images.forEach(function (image) {
            image.style.height = imageWidth + 'px';
        });
    }
}

//------------------图片放大-----------------------------
var hammerMask_survey = document.getElementById("hammer-mask_html");
var hammerBg_survey = document.getElementById("hammer-bg_html");
var hammerBox_survey = document.getElementById("hammer-box_html");
var hammerPage_survey = document.getElementById("hammer-page_html");
var hammerImg_survey = document.getElementById("image-big_html");
window.initHammer(hammerMask_survey, hammerBg_survey, hammerBox_survey, hammerPage_survey, hammerImg_survey);

function useHammer_survey(e, index, type) {
    //images: 图片url数组men
    hammerMask_survey.style.top = document.body.scrollTop + "px";
    hammerBg_survey.style.top = document.body.scrollTop + "px";

    switch (type) {
        case "nbq": window.showHammer_html(nbq_images_survey, index); break;
        case 'pdx': window.showHammer_html(pdx_images_survey, index); break;
        case 'dbx': window.showHammer_html(dbx_images_survey, index); break;
    }
}

function Check_survey() {
    var List = document.getElementsByTagName('li');
    for (var i = 0; i < List.length; i++) {
        var data = List[i].getElementsByClassName('content-span_survey');
        if (data.length != 0) {
            if (data[0].innerText == 'undefined') {
                console.log(i);
                data[0].innerText = '';
            }
        }
    }


}
